/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年9月17日 下午5:22:24
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniu.dao.StudentMapper;
import com.woniu.dao.StudentRepository;
import com.woniu.entity.Student;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/demo")
public class ControllerTest {
	@Autowired
	StudentRepository studentRepo;
	@Autowired
	StudentMapper stu;
	@RequestMapping("m1")
	public String m1() {
		return "index";
	}
	/**
	 * 单一jpa查询
	 * @return
	 */
	@RequestMapping("m2")
	@ResponseBody
	public List<Student> m2() {
		//List<User> list = jdbctpl.query("select * from stum", new MyRowMapper(User.class));
		return studentRepo.findBySex("男");
	}
	/**
	 * cariteria查询
	 * @return
	 */
	@RequestMapping("m3")
	@ResponseBody
	public List<Student> m3(){
		Student u = new Student();
		u.setSex("男");
		Example<Student> exm = Example.of(u);
		return studentRepo.findAll(exm);
	}
	/**
	 * jpql查询
	 * @return
	 */
	@RequestMapping("m4")
	@ResponseBody
	public List<Student> m4(){
		return studentRepo.findByName("李四");
	}
	/**
	 * sql查询
	 * @return
	 */
	@RequestMapping("m5")
	@ResponseBody
	public List<Student> m5(){
		return studentRepo.findByDepartment("中文系");
	}
	@RequestMapping("m6")
	@ResponseBody
	public List<Student> m6(String depart,String sex){
		return stu.selectAll(depart,sex);
	}
}

